package com.ruoyi.service.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.service.domain.ServiceItems;
import com.ruoyi.service.service.IServiceItemsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 服务项目Controller
 * 
 * @author ZDL
 * @date 2024-10-21
 */
@RestController
@RequestMapping("/service/items")
public class ServiceItemsController extends BaseController
{
    @Autowired
    private IServiceItemsService serviceItemsService;

    /**
     * 查询服务项目列表
     */
    @PreAuthorize("@ss.hasPermi('service:items:list')")
    @GetMapping("/list")
    public TableDataInfo list(ServiceItems serviceItems)
    {
        startPage();
        List<ServiceItems> list = serviceItemsService.selectServiceItemsList(serviceItems);
        return getDataTable(list);
    }

    /**
     * 导出服务项目列表
     */
    @PreAuthorize("@ss.hasPermi('service:items:export')")
    @Log(title = "服务项目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ServiceItems serviceItems)
    {
        List<ServiceItems> list = serviceItemsService.selectServiceItemsList(serviceItems);
        ExcelUtil<ServiceItems> util = new ExcelUtil<ServiceItems>(ServiceItems.class);
        util.exportExcel(response, list, "服务项目数据");
    }

    /**
     * 获取服务项目详细信息
     */
    @PreAuthorize("@ss.hasPermi('service:items:query')")
    @GetMapping(value = "/{itemId}")
    public AjaxResult getInfo(@PathVariable("itemId") Long itemId)
    {
        return success(serviceItemsService.selectServiceItemsByItemId(itemId));
    }

    /**
     * 新增服务项目
     */
    @PreAuthorize("@ss.hasPermi('service:items:add')")
    @Log(title = "服务项目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ServiceItems serviceItems)
    {
        return toAjax(serviceItemsService.insertServiceItems(serviceItems));
    }

    /**
     * 修改服务项目
     */
    @PreAuthorize("@ss.hasPermi('service:items:edit')")
    @Log(title = "服务项目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ServiceItems serviceItems)
    {
        return toAjax(serviceItemsService.updateServiceItems(serviceItems));
    }

    /**
     * 删除服务项目
     */
    @PreAuthorize("@ss.hasPermi('service:items:remove')")
    @Log(title = "服务项目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{itemIds}")
    public AjaxResult remove(@PathVariable Long[] itemIds)
    {
        return toAjax(serviceItemsService.deleteServiceItemsByItemIds(itemIds));
    }
}
